<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ include file="../include/admincontent.jsp" %>

<div id="location">当前位置：首页 > 招聘方案管理 > 添加招聘方案</div>
<div id="Content">
    <form id="Validform" method="post" action="/Project/AddAction">
        <input type="hidden" id="proid" value="0"/>
        <div class="btnbar">
            <button type="submit" class="save">保 存</button>
            <button type="button" class="back" onclick="javascript:history.go(-1);">返 回</button>
        </div>
        <table class="treeTable inputform">
            <thead>
            <tr>
                <td colspan="4"><b>基本信息</b></td>
            </tr>
            </thead>
            <tbody>
            <tr>
                <td width="65">方案名称：</td>
                <td>
                    <div style="width:300px;"><input type="text" name="project.pname" datatype="*" nullmsg="方案名称不能为空！"/>
                    </div>
                </td>
            </tr>
            <tr>
                <td>招聘方式：</td>
                <td>
                    <div class="radio">
                        <span rel="1" fdata="1">高校校园招聘</span>
                        <span rel="2" fdata="2">中专校园招聘</span>
                        <span rel="3" fdata="3">社会招聘</span>
                        <span rel="4" fdata="4">内部招聘</span>
                        <input type="hidden" id="recruittype" name="project.recruittype" value="1" datatype="*"
                               nullmsg="招聘方式不能为空！">
                    </div>
                </td>
            </tr>
            </tbody>
        </table>
        <!-- 统一流程配置,各个方案可自定义流程 -->
        <table class="treeTable inputform" style="margin-top:5px;" id="flows">
            <thead>
            <tr>
                <td colspan="4"><b>实施流程</b></td>
            </tr>
            <tr>
                <td width="80">流程顺序</td>
                <td width="200">流程内容</td>
                <td width="200">流程别名</td>
                <td>
                    <button type="button" onFocus="blur()" class="add"></button>
                </td>
            </tr>
            </thead>
            <tbody>
            </tbody>
        </table>
        <!-- 高校校园招聘流程 -->
        <%--<table class="treeTable inputform" style="margin-top:5px;" id="flow1">
            <thead>
            <tr>
                <td><b>实施流程</b></td>
            </tr>
            </thead>
            <tbody>
           <tr>
                <td>简历筛选&emsp;>&emsp;面试&emsp;>&emsp;背景调查&emsp;>&emsp;体检&emsp;>&emsp;岗位分配&emsp;>&emsp;录用</td>
            </tr>


            </tbody>
        </table>--%>

        <!-- 中专校园招聘流程 -->
        <%--<table class="treeTable inputform" style="margin-top:5px;display:none;" id="flow2">
            <thead>
            <tr>
                <td><b>实施流程</b></td>
            </tr>
            </thead>
            <tbody>
            <!-- <tr><td>毕业生推荐&emsp;>&emsp;初审&emsp;>&emsp;面试&emsp;>&emsp;投简历&emsp;>&emsp;背景调查&emsp;>&emsp;体检&emsp;>&emsp;岗位分配&emsp;>&emsp;实习&emsp;>&emsp;录用</td></tr> -->
            <tr>
                <td>毕业生推荐&emsp;>&emsp;初审&emsp;>&emsp;投简历&emsp;>&emsp;录用</td>
            </tr>
            </tbody>
        </table>--%>

        <!-- 社会招聘流程 -->
        <%--<table class="treeTable inputform" style="margin-top:5px; display:none;" id="flow3">
            <thead>
            <tr>
                <td colspan="4"><b>实施流程</b></td>
            </tr>
            <tr>
                <td width="80">流程顺序</td>
                <td width="200">流程内容</td>
                <td width="200">流程别名</td>
                <td>
                    <button type="button" onFocus="blur()" class="add"></button>
                </td>
            </tr>
            </thead>
            <tbody>
            <tr>
                <td>1</td>
                <td>简历筛选<input type="hidden" name="sflow[0].fid" value="0"/></td>
                <td>简历筛选<input type="hidden" name="sflow[0].nickname" value="简历筛选"/></td>
                <td></td>
            </tr>
            <tr>
                <td>2</td>
                <td>录用<input type="hidden" name="sflow[1].fid" value="7"/></td>
                <td>录用<input type="hidden" name="sflow[1].nickname" value="录用"/></td>
                <td></td>
            </tr>
            </tbody>
        </table>--%>

        <!-- 内部招聘流程 -->
        <%--<table class="treeTable inputform" style="margin-top:5px; display:none;" id="flow4">
            <thead>
            <tr>
                <td colspan="4"><b>实施流程</b></td>
            </tr>
            <tr>
                <td width="80">流程顺序</td>
                <td width="200">流程内容</td>
                <td width="200">流程别名</td>
                <td>
                    <button type="button" onFocus="blur()" class="add"></button>
                </td>
            </tr>
            </thead>
            <tbody>
            <tr>
                <td>1</td>
                <td>职位申请<input type="hidden" name="flow[0].fid" value="0"/></td>
                <td>职位申请<input type="hidden" name="flow[0].nickname" value="职位申请"/></td>
                <td></td>
            </tr>
            <tr>
                <td>2</td>
                <td>简历筛选<input type="hidden" name="flow[1].fid" value="1"/></td>
                <td>简历筛选<input type="hidden" name="flow[1].nickname" value="简历筛选"/></td>
                <td></td>
            </tr>
            <tr>
                <td>3</td>
                <td>录用<input type="hidden" name="flow[2].fid" value="4"/></td>
                <td>录用<input type="hidden" name="flow[2].nickname" value="录用"/></td>
                <td></td>
            </tr>
            </tbody>
        </table>--%>

        <!-- 招聘岗位 -->
        <table class="treeTable inputform" id="jobtb" style="margin-top:5px;">
            <thead>
            <tr>
                <td colspan="10"><b>招聘岗位</b></td>
            </tr>
            <tr>
                <td width="40">序号</td>
                <td>岗位名称</td>
                <td width="120">招聘人数</td>
                <td width="120">年龄</td>
                <td width="120">工作年限</td>
                <td width="120">学历</td>
                <td width="120">专业</td>
                <td width="120">性别</td>
                <td width="40">
                    <button type="button" onFocus="blur()" class="add"></button>
                </td>
            </tr>
            </thead>
            <tbody id="result"></tbody>
        </table>
        <input type="hidden" name="jobsList" id="jobsList" value="">
        <!-- 高校校园招聘地区 -->
        <%-- <table class="treeTable inputform" id="areagx" style="margin-top:5px;">
             <thead>
             <tr>
                 <td><b>招聘地区</b></td>
             </tr>
             </thead>
             <tbody id="arearst">
             <tr>
                 <td>
                     <div class=radio1>${areas}</div>
                 </td>
             </tr>
             </tbody>
         </table>--%>
    </form>
</div>
<script type="text/javascript">
    var checkData;
    var jobList = [];
    $(function () {
        showJobList($('#recruittype').val());

        //选择招聘方式
        $('.radio span').click(function () {
            /*$('table[id^=flow]').hide();
            $('#flow' + $(this).attr('fdata')).show();*/
            checkData = $(this).attr('fdata');
            showJobList($(this).attr('fdata'));
            fillFlows($(this).attr('fdata'));
        });

        $('#flows button.add').click(function () {
            if (checkData == 2) {

                var temp = '<tr><td>2</td><td><div><select name="flow[1].fid"><option value="1">初审</option><option value="2">面试</option><option value="4">背景调查</option><option value="5">体检</option><option value="7">实习</option></select></div></td>';
                temp += '<td><div><input type="text" name="flow[1].nickname" datatype="*" nullmsg="流程别名不能为空！"></div></td>';
                temp += '<td><button type="button" onfocus="blur()" class="del"></button></td></tr>';

                $('#flows tbody tr:last').before(temp);
                $('#flows tbody tr:last').prev().find('td:eq(2) input').val($('#flows tbody tr:last').prev().find('td:eq(1) select option:checked').text());
                setFlowStyle();
            } else
            if (checkData == 1 || checkData == 3) {

                var temp = '<tr><td>2</td><td><div><select name="flow[1].fid"><option value="1">笔试</option><option value="2">资料审核</option><option value="3">面试</option><option value="4">实作</option><option value="5">体检</option><option value="6">背景调查</option></select></div></td>';
                temp += '<td><div><input type="text" name="flow[1].nickname" datatype="*" nullmsg="流程别名不能为空！"></div></td>';
                temp += '<td><button type="button" onfocus="blur()" class="del"></button></td></tr>';

                $('#flows tbody tr:last').before(temp);
                $('#flows tbody tr:last').prev().find('td:eq(2) input').val($('#flows tbody tr:last').prev().find('td:eq(1) select option:checked').text());
                setFlowStyle();
            } else if (checkData == 4) {
                var temp = '<tr><td>2</td><td><div><select name="flow[1].fid"><option value="2">面试</option><option value="3">笔试</option></select></div></td>';
                temp += '<td><div><input type="text" name="flow[1].nickname" value="面试" datatype="*" nullmsg="流程别名不能为空！"></div></td>';
                temp += '<td><button type="button" onfocus="blur()" class="del"></button></td></tr>';

                $('#flows tbody tr:last').before(temp);
                setFlowStyle();
            } else {
                layer.msg('请先选择招聘方案的种类!', {
                    time: 5000, //5s后自动关闭
                    icon: 2
                });

            }

        });


        //删除流程
        $(document).delegate('#flows button.del', 'click', function () {
            $(this).parent().parent().remove();
            setFlowStyle();
        });

        //流程别名
        $(document).delegate('#flows select', 'change', function () {
            $(this).parent().parent().next().find('input').val($(this).find('option:checked').text());
            $(this).prev().val($(this).val());
        });

        //添加招聘岗位
        $('#jobtb button.add').click(function () {
            openLayer('添加招聘岗位', '/Project/AddJobByWeb?pid=${project.id}&ptype='+$('#recruittype').val(), '98%', '98%');
        });

        //删除招聘岗位
        $(document).delegate('#jobtb button.del', 'click', function () {
            var _obj = $(this);
            layer.confirm('确定要删除该岗位吗？', {
                btn: ['是', '否']
            }, function () {
                var row = _obj.parent().parent();
                var rowNum = $(row).index();
                jobList = jobList.slice(0, rowNum).concat(jobList.slice(rowNum + 1, jobList.length))
                //_obj.parent().parent().remove();
                fullJobList();
                layer.closeAll();
            }, function () {
                layer.closeAll();
            });
        });

        //修改招聘岗位
        $(document).delegate('#jobtb button.edit', 'click', function () {
            var _obj = $(this);
            var row = _obj.parent().parent();
            var rowNum = $(row).index();
            var url = '/Project/EditJobByWeb?id=' + rowNum+'&ptype='+$('#recruittype').val();
            openLayer('修改招聘岗位', url, '98%', '98%');
        });

        //删除招聘岗位
        $(document).delegate('#jobtb button.del', 'click', function () {
            $(this).parent().parent().remove();
            setJobStyle();
        });

        //招聘地区
        $(document).delegate('.inputform tbody div.radio1 span', 'click', function () {
            $(this).parent().find('input[type=hidden]').remove();
            if (!$(this).parent().hasClass('disables')) {
                if ($(this).hasClass('checked'))
                    $(this).removeClass('checked');
                else
                    $(this).addClass('checked');
                var i = 0;
                $(this).parent().find('span').each(function () {
                    if ($(this).hasClass('checked')) {
                        $(this).parent().append('<input type="hidden" name="region[' + i + '].rcode" value="' + $(this).attr('rel') + '" />');
                        $(this).parent().append('<input type="hidden" name="region[' + i + '].region" value="' + $(this).text() + '" />');
                        i++;
                    }
                });
            }
        });

        $('.radio span:first').click();
    });

    function fillFlows(data) {
        var temp = '';
        switch (parseInt(data)) {
            case 1:
                temp = createGXFlow();
                break;
            case 2:
                temp = createZZFlow();
                //temp = createGXFlow();
                break;
            case 3:
                temp = createSZFlow();
                break;
            case 4:
                temp = createNBFlow();
                break;
            default:
                break;
        }
        $('#flows tbody').empty();
        $('#flows tbody').append(temp);
        setFlowStyle();
    }

    //初始社招招聘流程
    function createSZFlow() {
        var temp = '<tr>'
            + ' <td>1</td>'
            + ' <td>简历筛选<input type="hidden" name="flow[0].fid" value="0"/></td>'
            + '     <td>简历筛选<input type="hidden" name="flow[0].nickname" value="简历筛选"/></td>'
            + '  <td></td>'
            + '  </tr>'
            + '    <tr>'
            + '    <td>2</td>'
            + '     <td>录用<input type="hidden" name="flow[1].fid" value="7"/></td>'
            + '    <td>录用<input type="hidden" name="flow[1].nickname" value="录用"/></td>'
            + '  <td></td>'
            + ' </tr> ';
        /* var temp = '<tr><td>2</td><td><div><select name="flow[1].fid"><option value="1">笔试</option><option value="2">资料审核</option><option value="3">面试</option><option value="4">实作</option><option value="5">体检</option><option value="6">背景调查</option></select></div></td>';
         temp += '<td><div><input type="text" name="flow[1].nickname" datatype="*" nullmsg="流程别名不能为空！"></div></td>';
         temp += '<td><button type="button" onfocus="blur()" class="del"></button></td></tr>';*/
        return temp;
    }

    //初始中专招聘流程
    function createZZFlow() {

        var temp = '<tr>\n' +
            '                <td>1</td>\n' +
            '                <td>毕业生推荐<input type="hidden" name="flow[0].fid" value="0"/></td>\n' +
            '                <td>毕业生推荐<input type="hidden" name="flow[0].nickname" value="毕业生推荐"/></td>\n' +
            '                <td></td>\n' +
            '            </tr>\n' +
            '            <tr>\n' +
            '                <td>4</td>\n' +
            '                <td>录用<input type="hidden" name="flow[1].fid" value="8"/></td>\n' +
            '                <td>录用<input type="hidden" name="flow[1].nickname" value="录用"/></td>\n' +
            '                <td></td>\n' +
            '            </tr>';
        return temp;
    }

    //初始高校招聘流程
    function createGXFlow() {
        /* var temp='<tr>\n' +
             '                <td>1</td>\n' +
             '                <td>简历筛选<input type="hidden" name="flow[0].fid" value="0"/></td>\n' +
             '                <td>简历筛选<input type="hidden" name="flow[0].nickname" value="简历筛选"/></td>\n' +
             '                <td></td>\n' +
             '            </tr>\n' +
             '            <tr>\n' +
             '                <td>2</td>\n' +
             '                <td>面试<input type="hidden" name="flow[1].fid" value="1"/></td>\n' +
             '                <td>面试<input type="hidden" name="flow[1].nickname" value="面试"/></td>\n' +
             '                <td><button type="button" onfocus="blur()" class="del"></button></td>\n' +
             '            </tr>\n' +
             '            <tr>\n' +
             '                <td>3</td>\n' +
             '                <td>背景调查<input type="hidden" name="flow[1].fid" value="2"/></td>\n' +
             '                <td>背景调查<input type="hidden" name="flow[1].nickname" value="背景调查"/></td>\n' +
             '                <td><button type="button" onfocus="blur()" class="del"></button></td>\n' +
             '            </tr>\n' +
             '            <tr>\n' +
             '                <td>4</td>\n' +
             '                <td>体检<input type="hidden" name="flow[1].fid" value="3"/></td>\n' +
             '                <td>体检<input type="hidden" name="flow[1].nickname" value="体检"/></td>\n' +
             '                <td><button type="button" onfocus="blur()" class="del"></button></td>\n' +
             '            </tr>\n' +
             '            <tr>\n' +
             '                <td>5</td>\n' +
             '                <td>岗位分配<input type="hidden" name="flow[1].fid" value="4"/></td>\n' +
             '                <td>岗位分配<input type="hidden" name="flow[1].nickname" value="岗位分配"/></td>\n' +
             '                <td><button type="button" onfocus="blur()" class="del"></button></td>\n' +
             '            </tr>\n' +
             '            <tr>\n' +
             '                <td>6</td>\n' +
             '                <td>录用<input type="hidden" name="flow[1].fid" value="5"/></td>\n' +
             '                <td>录用<input type="hidden" name="flow[1].nickname" value="录用"/></td>\n' +
             '                <td></td>\n' +
             '            </tr>';*/

        var temp = '<tr>'
            + ' <td>1</td>'
            + ' <td>简历筛选<input type="hidden" name="flow[0].fid" value="0"/></td>'
            + '     <td>简历筛选<input type="hidden" name="flow[0].nickname" value="简历筛选"/></td>'
            + '  <td></td>'
            + '  </tr>'
            + '            <tr>'
            + '                <td>2</td>'
            + '                <td>面试<input type="hidden" name="flow[1].fid" value="3"/></td>'
            + '                <td>面试<input type="hidden" name="flow[1].nickname" value="面试"/></td>'
            + '                <td><button type="button" onfocus="blur()" class="del"></button></td>'
            + '            </tr>'

            + '            <tr>'
            + '                <td>3</td>'
            + '                <td>体检<input type="hidden" name="flow[2].fid" value="5"/></td>'
            + '                <td>体检<input type="hidden" name="flow[2].nickname" value="体检"/></td>'
            + '                <td><button type="button" onfocus="blur()" class="del"></button></td>'
            + '            </tr>'
            + '           <tr>'
            + '                <td>4</td>'
            + '                <td>背景调查<input type="hidden" name="flow[3].fid" value="6"/></td>'
            + '                <td>背景调查<input type="hidden" name="flow[3].nickname" value="背景调查"/></td>'
            + '                <td><button type="button" onfocus="blur()" class="del"></button></td>'
            + '            </tr>'
            + '    <td>5</td>'
            + '     <td>录用<input type="hidden" name="flow[4].fid" value="7"/></td>'
            + '    <td>录用<input type="hidden" name="flow[4].nickname" value="录用"/></td>'
            + '  <td></td>'
            + ' </tr> ';
        return temp;
    }

    //初始内部招聘流程
    function createNBFlow() {
        var temp = '<tr>\n' +
            '                <td>1</td>\n' +
            '                <td>职位申请<input type="hidden" name="flow[0].fid" value="0"/></td>\n' +
            '                <td>职位申请<input type="hidden" name="flow[0].nickname" value="职位申请"/></td>\n' +
            '                <td></td>\n' +
            '            </tr>\n' +
            '            <tr>\n' +
            '                <td>2</td>\n' +
            '                <td>简历筛选<input type="hidden" name="flow[1].fid" value="1"/></td>\n' +
            '                <td>简历筛选<input type="hidden" name="flow[1].nickname" value="简历筛选"/></td>\n' +
            '                <td></td>\n' +
            '            </tr>\n' +
            '            <tr>\n' +
            '                <td>3</td>\n' +
            '                <td>录用<input type="hidden" name="flow[2].fid" value="4"/></td>\n' +
            '                <td>录用<input type="hidden" name="flow[2].nickname" value="录用"/></td>\n' +
            '                <td></td>\n' +
            '            </tr>'

        return temp;
    }

    //设置流程表单信息
    function setFlowStyle() {

        $('#flows tbody tr').each(function (index) {
            $(this).find('td:first').html(index + 1);
            if (index > 1 && index < $('#flows tbody tr').length - 1) {
                $(this).find('td:eq(1) select').attr('name', 'flow[' + index + '].fid');
                $(this).find('td:eq(2) input').attr('name', 'flow[' + index + '].nickname');
            } else {
                $(this).find('td:eq(1) input').attr('name', 'flow[' + index + '].fid');
                $(this).find('td:eq(2) input').attr('name', 'flow[' + index + '].nickname');
            }
        });


    }

    //设置岗位表单信息
    function setJobStyle() {
        $('#result tr').each(function (index) {
            $(this).find('td:first span').html(index + 1);
            $(this).find('td:first input').attr('name', 'job[' + index + '].did');
            $(this).find('td:eq(8) input').attr('name', 'job[' + index + '].zpcount');
        });
    }

    //显示或隐藏岗位列表
    function showJobList(str) {
        $('#jobtb').hide();
        $('#areagx').hide();
        /*if (str == '2') {
            $('#areagx').show();
        } else {
            $('#jobtb').show();
        }*/
        $('#jobtb').show();
    }

    //添加职位列表
    function fullJobList() {
        if (jobList.length > 0) {
            $("#jobtb tbody").empty();
            for (var i = 0; i < jobList.length; i++) {
                var job = jobList[i];
                var tr = $("<tr></tr>");
                tr.append($("<td>" + (i + 1) + "</td>"));
                tr.append($("<td>" + job.jobname + "</td>"));
                tr.append($("<td>" + job.zpcount + "</td>"))
                if (job.agef == null || job.aget == null) {
                    tr.append("<td>不限</td>");
                } else {
                    tr.append("<td>" + job.agef + "-" + job.aget + "</td>");
                }
                if (job.workyear == null || job.workyear.length == 0) {
                    tr.append("<td>不限</td>");
                } else {
                    tr.append("<td>" + job.workyear + "年以上</td>");
                }
                tr.append("<td>" + job.eduname + "</td>");
                if (job.major == null || job.major.length == 0) {
                    tr.append("<td>不限</td>");
                } else {
                    tr.append("<td>" + job.major + "</td>");
                }
                tr.append("<td>" + job.gender + "</td>");
                var ctd = $("<td></td>");
                ctd.append("<button type='button' onfocus='blur()' class='edit' id='edit_job_" + i + "'></button>");
                /* ctd.append("<input type='hidden'  value='" + i + "'>");
                 ctd.append("<input type='hidden'  value='" + job.istemplate + "'>");
                 ctd.append("<input type='hidden' value='" + job.required + "'>");
                 ctd.append("<input type='hidden' value='" + job.workreq + "'>");*/
                ctd.append("<button type='button' onfocus='blur()' class='del' id='del_job_\"+i+\"'></button>");
                tr.append(ctd);
                $("#jobtb tbody").append(tr);

            }
            var jss = JSON.stringify(jobList);
            $("#jobsList").val(jss);
        }
    }
</script>
</body>
</html>